package com.luoqiz.security.config.response;

import com.luoqiz.common.httpEntity.HttpResponseBase;
import com.luoqiz.common.httpEntity.HttpResponseService;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;

import java.util.HashMap;
import java.util.Map;


public class HandlerMethodReturnValueHandlerProxy implements HandlerMethodReturnValueHandler {

	private static final int STATUS_CODE_SUCCEEDED = 200;

	private HandlerMethodReturnValueHandler proxyObject;

	public HandlerMethodReturnValueHandlerProxy(HandlerMethodReturnValueHandler proxyObject) {
		this.proxyObject = proxyObject;
	}

	@Override
	public boolean supportsReturnType(MethodParameter returnType) {
		return proxyObject.supportsReturnType(returnType);
	}

	@Override
	public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
			NativeWebRequest webRequest) throws Exception {
		Map<String,Object> map=new HashMap<>();
		HttpResponseBase hs = HttpResponseService.setSuccess(STATUS_CODE_SUCCEEDED + "", "操作成功", returnValue);
		proxyObject.handleReturnValue(hs, returnType, mavContainer, webRequest);
	}

}
